package com.tutu.product.listener;

import com.tutu.commons.to.OrderToProduct;
import com.tutu.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Program: b2c-cloud-store
 * @Description: 监听rabbitmq的消息
 * @Author: JK.TuTu
 * @Version: 1.0
 * @Create: 2022-12-28 19:59
 **/
@Slf4j
@Component
public class RabbitMqListener {

    @Autowired
    private ProductService productService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "sub.queueu"),
            exchange = @Exchange(value = "topic.ex",type = ExchangeTypes.TOPIC),
            key = "sub.number"))
    public void updateProduct(List<OrderToProduct> orderToProducts) {
        log.info("接收到的消息是:{}", orderToProducts);
        //调用业务层方法 更新商品信息
        productService.updateProduct(orderToProducts);
    }

}
